# visual.py
# script for visualizing clingo output will be more general later


import sys
import pyExcelerator

resMap = {}
MAX_WEEKS = 0

def main( scu ) :
    input = scu  
    #input = sys.rdin  
    MAX_WEEKS = 0
    resultList = input.split(" ")
    #print resultList
    resultList = resultList[0:len(resultList)-2]
    resultList = [tuple(x[4:-1].split(",")) for x in resultList]
    resultList = [(a,b,c,int(d)) for a,b,c,d in resultList]
    weekDict = {}
    i=0
    for cur in resultList:
        week = cur[3]
        if int(week) > MAX_WEEKS :
            MAX_WEEKS = week
        if week not in weekDict:
            weekDict[week] = []
        weekDict[week].append(cur)
    resMap[i] = weekDict
    i+=1
	

	# At this point, each schedule is loaded into the resMap 
	# with all of its weeks divided up for ease of use in creating the spreadsheet
    create()
	
	
def create() :
	#for each schedule given...
	for key in resMap : 
		docSheet = w.add_sheet("schedule " + str(key))
		metaMap = resMap[key]
		for metaKey in sorted(metaMap.iterkeys()) :
			#Goin through each week in the current schedule
			curList = metaMap[metaKey]
			index = 0
			for match in curList :
				docSheet.write(int(index),int(metaKey), str(match))
				docSheet.col(int(metaKey)).width = 13*256
				index+=1
				
	
	w.save("visuals.xls")
			

			
w = pyExcelerator.Workbook()
#main()
